package cn.hznc.controller.service.toolfork;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil;
import cn.hznc.configuration.MinioHelper;
import cn.hznc.constant.CommonConstant;
import cn.hznc.constant.ToolConstant;
import cn.hznc.domain.entity.*;
import cn.hznc.domain.request.toolfork.*;
import cn.hznc.domain.response.PageResult;
import cn.hznc.exception.ToolManageEx;
import cn.hznc.exception.ToolManageException;
import cn.hznc.mapper.*;
import cn.hznc.repository.ToolForkInfoRespository;
import cn.hznc.repository.ToolInventoryLocationRespository;
import cn.hznc.repository.ToolPartRespository;
import cn.hznc.utils.CommonUtil;
import cn.hznc.utils.UUIDUtil;
import cn.hznc.vo.*;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;


/**
 * 总成服务接口
 */
@Service
public class AssemblyToolService {

    @Resource
    private AssemblyToolMapper assemblyToolMapper;

    @Resource
    private TypeItemMapper typeItemMapper;

    @Resource
    private ToolForkInfoMapper toolForkInfoMapper;

    @Resource
    private ToolForkInfoRespository toolForkInfoRespository;

    @Resource
    private AssemblyToolConnectMapper assemblyToolConnectMapper;

    @Resource
    private AssemblyToolTypeMapper assemblyToolTypeMapper;

    @Resource
    private TransferParamMapper transferParamMapper;

    @Resource
    private EmployeeMapper employeeMapper;

    @Autowired
    private MinioHelper minioHelper;

    @Autowired
    private MinioProp minioProp;

    @Resource
    private ToolPartRespository toolPartRespository;

    @Resource
    private ToolInventoryLocationRespository toolInventoryLocationRespository;

    @Resource
    private TransferParamChildMapper transferParamChildMapper;

    @Resource
    private AssemblyMountingDistanceMapper assemblyMountingDistanceMapper;

    @Resource
    private AssembleTaskMapper assembleTaskMapper;



    /**
     * 创建总成刀具接口
     *
     * @return boolean
     */
//    public AssemblyToolEntity createAssemblyTool(CreateAssemblyToolReq createAssemblyToolReq) throws ToolManageException {
//        // 获取刀具关联关系-----无关系不能创建
//        AssemblyToolConnectEntity assemblyToolConnectEntity = getAssemblyToolConnectEntity(createAssemblyToolReq);
//        if (Objects.isNull(assemblyToolConnectEntity)){
//            throw new ToolManageException(ToolManageEx.ASSEMBLY_TOOL_NO_EXIST.getCode(),ToolManageEx.ASSEMBLY_TOOL_NO_EXIST.getMsg());
//        }
//        AssemblyToolEntity assemblyToolEntity = buildAssemblyToolEntity(createAssemblyToolReq, assemblyToolConnectEntity);
//        assemblyToolMapper.insert(assemblyToolEntity);
//        return assemblyToolEntity;
//    }

//    private AssemblyToolEntity buildAssemblyToolEntity(CreateAssemblyToolReq createAssemblyToolReq, AssemblyToolConnectEntity assemblyToolConnectEntity) {
//        AssemblyToolEntity assemblyToolEntity = new AssemblyToolEntity();
//        assemblyToolEntity.setCode(UUIDUtil.getUUID());
//        assemblyToolEntity.setName("总成"+"-"+assemblyToolEntity.getCode().substring(0,5));
//        assemblyToolEntity.setCutterId(createAssemblyToolReq.getCutterId());
//        assemblyToolEntity.setAuxiliaryToolId(createAssemblyToolReq.getAuxiliaryToolId());
//        assemblyToolEntity.setToolId(createAssemblyToolReq.getToolId());
//        assemblyToolEntity.setType(createAssemblyToolReq.getType());
//        assemblyToolEntity.setImage(assemblyToolConnectEntity.getImage());
//        assemblyToolEntity.setThreeDimensionalModel(assemblyToolConnectEntity.getThreeDimensionalModel());
//        assemblyToolEntity.setModifyTime(new Date());
//        assemblyToolEntity.setCreateTime(new Date());
//        ArrayList<Integer> toolIds = new ArrayList<>();
//        toolIds.add(createAssemblyToolReq.getToolId());
//        if (!StringUtils.isEmpty(createAssemblyToolReq.getAuxiliaryToolType())){
//            toolIds.add(createAssemblyToolReq.getAuxiliaryToolId());
//        }
//        toolIds.add(createAssemblyToolReq.getCutterId());
//        List<Parameter> parameters = buildParameters(assemblyToolConnectEntity, toolIds);
//        assemblyToolEntity.setParameters(JSON.toJSONString(parameters));
//        return assemblyToolEntity;
//    }
    private List<Parameter> buildParameters(AssemblyToolConnectEntity assemblyToolConnectEntity, ArrayList<Integer> toolIds) {
        List<ToolForkInfoEntity> toolForkInfoEntities = toolForkInfoMapper.selectBatchIds(toolIds);
        List<Parameter> parameters = toolForkInfoEntities.stream().map(this::getParameter).collect(Collectors.toList());
        for (Parameter parameter : parameters) {
            if (parameter.getType().startsWith(ToolConstant.CUTTER_TYPE)) {
                // 单独设置刀片数量
                parameter.setNum(assemblyToolConnectEntity.getCutterNum());
            } else {
                // 其他情况设置成1
                parameter.setNum(1);
            }
        }
        return parameters;
    }

//    private AssemblyToolConnectEntity getAssemblyToolConnectEntity(CreateAssemblyToolReq createAssemblyToolReq) {
//        QueryWrapper<AssemblyToolConnectEntity> wrapper = new QueryWrapper<>();
//        if(!"none".equals(createAssemblyToolReq.getForkType())){
//            wrapper.eq("fork_type",createAssemblyToolReq.getForkType());
//        }
//        if(!"none".equals(createAssemblyToolReq.getCutterType())){
//            wrapper.eq("cutter_type",createAssemblyToolReq.getCutterType());
//        }
//        if(!"none".equals(createAssemblyToolReq.getAuxiliaryToolType())){
//            wrapper.eq("auxiliary_tool_type",createAssemblyToolReq.getAuxiliaryToolType());
//        }
//        return assemblyToolConnectMapper.selectOne(wrapper);
//    }

    private Parameter getParameter(ToolForkInfoEntity toolForkInfoEntity) {
        Parameter parameter = new Parameter();
        parameter.setIdnr(toolForkInfoEntity.getIdnr());
        parameter.setPartno(toolForkInfoEntity.getPartno());
        parameter.setGrdmfg(toolForkInfoEntity.getGrdmfg());
        parameter.setType(toolForkInfoEntity.getType());
        return parameter;
    }

    /**
     * 编辑总成工具(根据id更新)
     *
     * @param editAssemblyToolReq 编辑请求参数
     * @return boolean
     */
    public boolean editAssemblyTool(EditAssemblyToolReq editAssemblyToolReq) throws ToolManageException {
        // 校验参数
        if (Objects.isNull(editAssemblyToolReq.getId())) {
            throw new ToolManageException(ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getCode(), ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getMsg());
        }
        AssemblyToolTypeEntity assemblyToolTypeEntity = assemblyToolTypeMapper.selectById(editAssemblyToolReq.getId());
        if (assemblyToolTypeEntity.getName().equals(editAssemblyToolReq.getName()) && assemblyToolTypeEntity.getToolNo().equals(editAssemblyToolReq.getToolNo())) {
            return Boolean.TRUE;
        } else {
            LambdaUpdateWrapper<AssemblyToolTypeEntity> Wrapper = new LambdaUpdateWrapper<>();
            if (StringUtils.isNotEmpty(editAssemblyToolReq.getName()) && !assemblyToolTypeEntity.getName().equals(editAssemblyToolReq.getName())) {
                Wrapper.eq(AssemblyToolTypeEntity::getName, editAssemblyToolReq.getName())
                        .eq(AssemblyToolTypeEntity::getType, assemblyToolTypeEntity.getType());
            } else if (StringUtils.isNotEmpty(editAssemblyToolReq.getToolNo()) && !assemblyToolTypeEntity.getName().equals(editAssemblyToolReq.getToolNo())) {
                Wrapper.eq(AssemblyToolTypeEntity::getToolNo, editAssemblyToolReq.getToolNo())
                        .eq(AssemblyToolTypeEntity::getType, assemblyToolTypeEntity.getType());
            }
            Integer count = Math.toIntExact(assemblyToolTypeMapper.selectCount(Wrapper));
            if (count > 0) {
                throw new ToolManageException(ToolManageEx.ASSEMBLY_TOOL_NAME_NO_EXIST.getCode(), ToolManageEx.ASSEMBLY_TOOL_NAME_NO_EXIST.getMsg());
            } else {
                assemblyToolTypeEntity.setName(editAssemblyToolReq.getName());
                assemblyToolTypeEntity.setToolNo(editAssemblyToolReq.getToolNo());
                assemblyToolTypeMapper.updateById(assemblyToolTypeEntity);
                return Boolean.TRUE;
            }
        }
    }

    /**
     * 删除总成工具
     *
     * @param ids ids
     * @return boolean
     */
    public boolean deleteAssemblyTool(List<Integer> ids) throws ToolManageException {
        // 校验参数
        if (CollectionUtils.isEmpty(ids)) {
            throw new ToolManageException(ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getCode(), ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getMsg());
        }
        assemblyToolTypeMapper.deleteBatchIds(ids);
        return Boolean.TRUE;
    }

    /**
     * 查询总成工具
     *
     * @param queryAssemblyToolReq queryAssemblyToolReq
     * @return
     */
    public PageResult<AssemblyToolVo> queryAssemblyTool(QueryAssemblyToolReq queryAssemblyToolReq) {
        PageHelper.startPage(queryAssemblyToolReq.getPageNum(), queryAssemblyToolReq.getPageSize());
        LambdaQueryWrapper<AssemblyToolTypeEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AssemblyToolTypeEntity::getUserId, queryAssemblyToolReq.getUserId());
        if (StringUtils.isNotEmpty(queryAssemblyToolReq.getName())) {
            wrapper.like(AssemblyToolTypeEntity::getName, queryAssemblyToolReq.getName());
        }
        PageInfo<AssemblyToolTypeEntity> pageInfo = new PageInfo<>(assemblyToolTypeMapper.selectList(wrapper));
        List<AssemblyToolVo> assemblyToolVos = pageInfo.getList().stream().map(this::transferAssemblyToolVo).collect(Collectors.toList());
        return new PageResult<>(assemblyToolVos, pageInfo.getTotal());
    }

    /**
     * 查询接口
     *
     * @param queryToolDetail queryToolDetail
     */
    public AssemblyToolDetailVo queryAssemblyToolDetail(QueryToolDetail queryToolDetail) throws ToolManageException {
        AssemblyToolTypeEntity assemblyToolTypeEntity = assemblyToolTypeMapper.selectById(queryToolDetail.getToolId());
        if (Objects.isNull(assemblyToolTypeEntity)) {
            throw new ToolManageException(ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getCode(), ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getMsg());
        }
        return buildAssemblyToolDeatil(assemblyToolTypeEntity);
    }

    private AssemblyToolDetailVo transferAssemblyToolVo(AssemblyToolTypeEntity assemblyToolTypeEntity) {
        AssemblyToolDetailVo assemblyToolDetailVo = new AssemblyToolDetailVo();
        assemblyToolDetailVo.setId(assemblyToolTypeEntity.getId());
        assemblyToolDetailVo.setPartIds(assemblyToolTypeEntity.getPartIds());
        assemblyToolDetailVo.setCode(assemblyToolTypeEntity.getCode());
        assemblyToolDetailVo.setType(assemblyToolTypeEntity.getType());
        assemblyToolDetailVo.setName(assemblyToolTypeEntity.getName());
        assemblyToolDetailVo.setCreateTime(assemblyToolTypeEntity.getCreateTime());
        assemblyToolDetailVo.setModifyTime(assemblyToolTypeEntity.getModifyTime());
        assemblyToolDetailVo.setImage(assemblyToolTypeEntity.getImage());
        assemblyToolDetailVo.setToolNo(assemblyToolTypeEntity.getToolNo());
        assemblyToolDetailVo.setToolLength(assemblyToolTypeEntity.getToolLength());
        assemblyToolDetailVo.setToolRadius(assemblyToolTypeEntity.getToolRadius());
        if (StringUtils.isNotEmpty(assemblyToolTypeEntity.getParameters()) && !assemblyToolTypeEntity.getParameters().equals("[]")) {
            List<AssemblyToolParamVo> assemblyToolParamVos = JSONArray.parseArray(assemblyToolTypeEntity.getParameters(), AssemblyToolParamVo.class);
//            assemblyToolDetailVo.setLength(assemblyToolParamVo.getLength());
//            assemblyToolDetailVo.setOal(assemblyToolParamVo.getOal());
            assemblyToolDetailVo.setAssemblyToolParamVos(assemblyToolParamVos);
        }
//        String baseUrl = minioProp.getBaseUrl() + minioProp.getBucketName() + "/";
//        String httpsBaseUrl = minioProp.getHttpsBaseUrl() + minioProp.getBucketName() + "/";
        assemblyToolDetailVo.setThreeDimensionalModel(assemblyToolTypeEntity.getThreeDimensionalModel());
        assemblyToolDetailVo.setThreeDimensionalModelStl(assemblyToolTypeEntity.getThreeDimensionalModelStl());
        return assemblyToolDetailVo;
    }

    private AssemblyToolDetailVo buildAssemblyToolDeatil(AssemblyToolTypeEntity assemblyToolTypeEntity) {
        AssemblyToolDetailVo assemblyToolDetailVo = transferAssemblyToolVo(assemblyToolTypeEntity);
        transferParameters(assemblyToolDetailVo);
//        List<Parameter> parameters = JSONArray.parseArray(assemblyToolTypeEntity.getParameters(), Parameter.class);
//        //assemblyToolDetailVo.setImage(assemblyToolEntity.getImage());
//        //assemblyToolDetailVo.setThreeDimensionalModel(assemblyToolEntity.getThreeDimensionalModel());
//        assemblyToolDetailVo.setParameters(parameters);
        return assemblyToolDetailVo;
    }

    private void transferParameters(AssemblyToolDetailVo assemblyToolDetailVo) {
        if (StringUtils.isNotEmpty(assemblyToolDetailVo.getPartIds()) || assemblyToolDetailVo.getPartIds() != "[]") {
            List<ToolPartsVos> ids = JSONArray.parseArray(assemblyToolDetailVo.getPartIds(), ToolPartsVos.class);
            if (CollectionUtil.isNotEmpty(ids)) {
                List<Parameter> parameters = new ArrayList<>();
                ids.forEach(toolPartVo -> {
                    ToolForkInfoEntity toolForkInfoEntity = toolForkInfoMapper.selectById(toolPartVo.getId());
                    if (ObjectUtil.isNotNull(toolForkInfoEntity)) {
                        Parameter parameter = new Parameter();
                        parameter.setGrdmfg(toolForkInfoEntity.getGrdmfg());
                        parameter.setIdnr(toolForkInfoEntity.getIdnr());
                        parameter.setPartno(toolForkInfoEntity.getPartno());
                        parameter.setType(toolForkInfoEntity.getType());
                        parameters.add(parameter);
                    }
                });
                assemblyToolDetailVo.setParameters(parameters);
            }
        }
    }

    public Boolean uploadFile(MultipartFile threeDimensionalModel, MultipartFile threeDimensionalModelStl, String name, String flag) throws ToolManageException {
//        QueryWrapper<AssemblyToolEntity> wrapper = new QueryWrapper<>();
//        wrapper.eq("code", code);
//        AssemblyToolEntity assemblyToolEntity = assemblyToolMapper.selectOne(wrapper);
        QueryWrapper<AssemblyToolTypeEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("name" , name);
        AssemblyToolTypeEntity assemblyToolTypeEntity = assemblyToolTypeMapper.selectOne(wrapper);
        if (ObjectUtil.isNull(assemblyToolTypeEntity)) {
            throw new ToolManageException(ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getCode(), ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getMsg());
        }
        if (ObjectUtil.isNotNull(threeDimensionalModel)) {
            String filename = assemblyToolTypeEntity.getName() + ".stp";
//            Context context = new Context();
//            context.uploadByStrategy(flag , threeDimensionalModel , filename);
            minioHelper.uploadFile(threeDimensionalModel, filename);
            assemblyToolTypeEntity.setThreeDimensionalModel(filename);
        }
        if (ObjectUtil.isNotNull(threeDimensionalModelStl)) {
            String filename = assemblyToolTypeEntity.getName() + ".stl";
//            Context context = new Context();
//            context.uploadByStrategy(flag , threeDimensionalModelStl , filename);
            minioHelper.uploadFile(threeDimensionalModelStl, filename);
            assemblyToolTypeEntity.setThreeDimensionalModelStl(filename);
        }
        assemblyToolTypeMapper.updateById(assemblyToolTypeEntity);
        return Boolean.TRUE;
    }

    public Object createAssemblyTool(CreateAssemblyToolReq createAssemblyToolReq) {
        QueryWrapper<TypeItemEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("type", createAssemblyToolReq.getType());
        TypeItemEntity typeItemEntity = typeItemMapper.selectOne(wrapper);
        AssemblyToolTypeEntity assemblyToolTypeEntity = new AssemblyToolTypeEntity();
        assemblyToolTypeEntity.setToolNo("");
        assemblyToolTypeEntity.setPartIds(JSONArray.toJSONString(createAssemblyToolReq.getIds()));
        assemblyToolTypeEntity.setUserId(createAssemblyToolReq.getUserId());
        assemblyToolTypeEntity.setCode(UUIDUtil.getUUID());
        assemblyToolTypeEntity.setName("总成" + "-" + assemblyToolTypeEntity.getCode().substring(0, 5));
        assemblyToolTypeEntity.setType(typeItemEntity.getTypeName());
        assemblyToolTypeEntity.setTypeCode(createAssemblyToolReq.getType());
        assemblyToolTypeEntity.setCreateTime(new Date());
        assemblyToolTypeEntity.setToolId(createAssemblyToolReq.getToolId());
        assemblyToolTypeMapper.insert(assemblyToolTypeEntity);
        //装配距离中间表中加入数据
        if(ObjectUtil.isNotNull(createAssemblyToolReq.getToolId()) &&
        ObjectUtil.isNotNull(createAssemblyToolReq.getMountingDistance()) && createAssemblyToolReq.getMountingDistance()>0){
            AssemblyMountingDistanceEntity assemblyMountingDistanceEntity = new AssemblyMountingDistanceEntity();
            assemblyMountingDistanceEntity.setAssemblyToolTypeId(assemblyToolTypeEntity.getId());
            assemblyMountingDistanceEntity.setToolForkInfoId(createAssemblyToolReq.getToolId());
            assemblyMountingDistanceEntity.setMountingDistance(createAssemblyToolReq.getMountingDistance());
            assemblyMountingDistanceMapper.insert(assemblyMountingDistanceEntity);
        }
        return assemblyToolTypeEntity;
    }

    public Object editAssemblyToolParams(EditAssemblyToolParamReloadReq editAssemblyToolParamsReq) throws ToolManageException {
        if (ObjectUtil.isNull(editAssemblyToolParamsReq.getId())) {
            throw new ToolManageException(ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getCode(), ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getMsg());
        }
        AssemblyToolTypeEntity assemblyToolTypeEntity = assemblyToolTypeMapper.selectById(editAssemblyToolParamsReq.getId());
        if(ObjectUtil.isNotNull(editAssemblyToolParamsReq.getToolLength())){
            assemblyToolTypeEntity.setToolLength(editAssemblyToolParamsReq.getToolLength());
        }
        if(ObjectUtil.isNotNull(editAssemblyToolParamsReq.getToolRadius())){
            assemblyToolTypeEntity.setToolRadius(editAssemblyToolParamsReq.getToolRadius());
        }
        assemblyToolTypeMapper.updateById(assemblyToolTypeEntity);
        return Boolean.TRUE;
    }

    public Object GetToolListWithPages(GetToolListReq getToolListReq) {
        List<AssemblyToolTypeVo> assemblyToolTypeVos = new ArrayList<>();
        List<AssemblyToolTypeVo> pageList = new ArrayList<>();
        List<Integer> userIds = getUserListByDepartment(getToolListReq.getDepartmentName());

        QueryWrapper<AssemblyToolTypeEntity> assembleWrapper = new QueryWrapper<>();
        assembleWrapper.in("user_id", userIds);
        List<AssemblyToolTypeEntity> assemblyToolTypeEntities = assemblyToolTypeMapper.selectList(assembleWrapper);
        if (CollectionUtil.isNotEmpty(assemblyToolTypeEntities)) {
            assemblyToolTypeEntities.forEach(assemblyToolTypeEntity -> {
                List<ToolPartsVos> ids = JSONArray.parseArray(assemblyToolTypeEntity.getPartIds(), ToolPartsVos.class);
                if (CollectionUtil.isNotEmpty(ids)) {
                    ids.forEach(toolPartsVos -> {
                        if (toolPartsVos.getType().equals(3)) {
                            //根据刀片类型匹配筛选
                            QueryWrapper<TransferParamEntity> queryWrapper = new QueryWrapper<>();
                            queryWrapper.eq("ug_param", getToolListReq.getType());
                            List<TransferParamEntity> transferParamEntities = transferParamMapper.selectList(queryWrapper);
                            ToolForkInfoEntity toolForkInfoEntity = toolForkInfoMapper.selectById(toolPartsVos.getId());
                            if (ObjectUtil.isNotNull(toolForkInfoEntity) && CollectionUtil.isNotEmpty(transferParamEntities)) {
                                //判断刀片类型是否属于转换表中类型
                                for (TransferParamEntity transferParamEntity : transferParamEntities) {
                                    if (toolForkInfoEntity.getType().contains(transferParamEntity.getToolManagementParamCode())) {
                                        AssemblyToolTypeVo assemblyToolTypeVo = new AssemblyToolTypeVo();
                                        assemblyToolTypeVo.setType(getToolListReq.getType());
                                        assemblyToolTypeVo.setName(assemblyToolTypeEntity.getName());
                                        assemblyToolTypeVo.setID(assemblyToolTypeEntity.getToolNo());
                                        //设置长度L 半径D
                                        String parameters = assemblyToolTypeEntity.getParameters();
//                                        if (StringUtils.isNotEmpty(parameters) && !parameters.equals("[]")) {
//                                            AssemblyToolParamVo assemblyToolParamVo = JSONObject.parseObject(parameters, AssemblyToolParamVo.class);
//                                            assemblyToolTypeVo.setD(Double.valueOf(assemblyToolParamVo.getLength()));
//                                            assemblyToolTypeVo.setL(Double.valueOf(assemblyToolParamVo.getOal()));
//                                        }
                                        //设置库存状态标志
                                        Integer number = toolPartRespository.countByToolNo(assemblyToolTypeEntity.getToolNo());
                                        if (ObjectUtil.isNotNull(number) && number > 0) {
                                            assemblyToolTypeVo.setFlag(1);
                                            assemblyToolTypeVo.setStockQuantity(number);
                                        } else {
                                            assemblyToolTypeVo.setFlag(0);
                                            assemblyToolTypeVo.setStockQuantity(0);
                                        }
                                        assemblyToolTypeVos.add(assemblyToolTypeVo);
                                    }
                                }
                            }
                        }
                    });
                }
            });
        }
        pageList = CommonUtil.pageList(assemblyToolTypeVos, getToolListReq.getPageIndex(), getToolListReq.getPageSize());
        return new PageResult<>(pageList, (long) assemblyToolTypeVos.size());
    }

    public Object GetToolListTransferByChildWithPages(GetToolListReq getToolListReq) {
        List<AssemblyToolTypeVo> assemblyToolTypeVos = new ArrayList<>();
        List<AssemblyToolTypeVo> pageList = new ArrayList<>();
        List<Integer> userIds = getUserListByDepartment(getToolListReq.getDepartmentName());

        QueryWrapper<AssemblyToolTypeEntity> assembleWrapper = new QueryWrapper<>();
        assembleWrapper.in("user_id", userIds);
        assembleWrapper.isNotNull("tool_no");
        List<AssemblyToolTypeEntity> assemblyToolTypeEntities = assemblyToolTypeMapper.selectList(assembleWrapper);
        if(CollectionUtil.isNotEmpty(assemblyToolTypeEntities)){
            assemblyToolTypeEntities = assemblyToolTypeEntities
                    .stream()
                    .filter(assemblyToolTypeEntity ->StringUtils.isNotBlank(assemblyToolTypeEntity.getToolNo()))
                    .collect(Collectors.toList());
        }
        if (CollectionUtil.isNotEmpty(assemblyToolTypeEntities)) {
            assemblyToolTypeEntities.forEach(assemblyToolTypeEntity -> {
                List<ToolPartsVos> ids = JSONArray.parseArray(assemblyToolTypeEntity.getPartIds(), ToolPartsVos.class);
                if (CollectionUtil.isNotEmpty(ids)) {
                    ids.forEach(toolPartsVos -> {
                        if (toolPartsVos.getType().equals(3)) {
                            //根据刀片类型匹配筛选
                            QueryWrapper<TransferParamChild> queryWrapper = new QueryWrapper<>();
                            queryWrapper.eq("ug_param", getToolListReq.getType());
                            List<TransferParamChild> transferParamEntities = transferParamChildMapper.selectList(queryWrapper);
                            ToolForkInfoEntity toolForkInfoEntity = toolForkInfoMapper.selectById(toolPartsVos.getId());
                            if (ObjectUtil.isNotNull(toolForkInfoEntity) && CollectionUtil.isNotEmpty(transferParamEntities)) {
                                //判断刀片类型是否属于转换表中类型
                                for (TransferParamChild transferParamChild : transferParamEntities) {
                                    if (StringUtils.isNotBlank(transferParamChild.getToolManagementParamCode()) && toolForkInfoEntity.getType().contains(transferParamChild.getToolManagementParamCode())) {
                                        AssemblyToolTypeVo assemblyToolTypeVo = new AssemblyToolTypeVo();
                                        assemblyToolTypeVo.setType(getToolListReq.getType());
                                        assemblyToolTypeVo.setName(assemblyToolTypeEntity.getName());
                                        assemblyToolTypeVo.setID(assemblyToolTypeEntity.getToolNo());
                                        //设置长度L 半径D
                                        String parameters = assemblyToolTypeEntity.getParameters();
//                                        if (StringUtils.isNotEmpty(parameters) && !parameters.equals("[]")) {
//                                            AssemblyToolParamVo assemblyToolParamVo = JSONObject.parseObject(parameters, AssemblyToolParamVo.class);
//                                            assemblyToolTypeVo.setD(Double.valueOf(assemblyToolParamVo.getLength()));
//                                            assemblyToolTypeVo.setL(Double.valueOf(assemblyToolParamVo.getOal()));
//                                        }
                                        //设置库存状态标志
                                        Integer number = toolPartRespository.countByToolNo(assemblyToolTypeEntity.getToolNo());
                                        if (ObjectUtil.isNotNull(number) && number > 0) {
                                            assemblyToolTypeVo.setFlag(1);
                                            assemblyToolTypeVo.setStockQuantity(number);
                                        } else {
                                            assemblyToolTypeVo.setFlag(0);
                                            assemblyToolTypeVo.setStockQuantity(0);
                                        }
                                        assemblyToolTypeVos.add(assemblyToolTypeVo);
                                    }
                                }
                            }
                        }
                    });
                }
            });
        }
        pageList = CommonUtil.pageList(assemblyToolTypeVos, getToolListReq.getPageIndex(), getToolListReq.getPageSize());
        return new PageResult<>(pageList, (long) assemblyToolTypeVos.size());
    }

    @NotNull
    private List<Integer> getUserListByDepartment(String department) {
        QueryWrapper<EmployeeEntity> empWrapper = new QueryWrapper<>();
        empWrapper.eq("department", department);
        List<EmployeeEntity> employeeEntities = employeeMapper.selectList(empWrapper);
        List<Integer> userIds = employeeEntities.stream().map(EmployeeEntity::getUserId).collect(Collectors.toList());
        return userIds;
    }

    public Object GetTool(String id, String department , String name) {
        ToolPartParamVo toolPartParamVo = new ToolPartParamVo();
        if(StringUtils.isBlank(id)){
            return toolPartParamVo;
        }
        List<Map<String, Object>> paramsList = new ArrayList<>();
        List<AssemblyToolTypeEntity> assemblyToolTypeEntities = getAssemblyToolTypeEntities(id, department , name);
        if (CollectionUtil.isEmpty(assemblyToolTypeEntities)) {
            return toolPartParamVo;
        }
        assemblyToolTypeEntities = assemblyToolTypeEntities.stream().filter(assemblyToolTypeEntity -> StringUtils.isNotBlank(assemblyToolTypeEntity.getName()) && StringUtils.isNotBlank(assemblyToolTypeEntity.getToolNo())).collect(Collectors.toList());
        AssemblyToolTypeEntity assemblyToolTypeEntity = assemblyToolTypeEntities.get(0);
        toolPartParamVo.setID(id);
        toolPartParamVo.setType(assemblyToolTypeEntity.getType());
        toolPartParamVo.setName(assemblyToolTypeEntity.getName());
        //转换类型
        String partIds = assemblyToolTypeEntity.getPartIds();
        List<ToolPartsVos> toolPartsVos = JSONArray.parseArray(partIds, ToolPartsVos.class);
        if (CollectionUtil.isNotEmpty(toolPartsVos)) {
            //List<TransferParamEntity> transferParamEntities = transferParamMapper.selectList(new QueryWrapper<>());
            toolPartsVos.forEach(toolPartsVo -> {
                Map<String, Object> params = new HashMap<>();
                if (toolPartsVo.getType().equals(1)) {
                    params.put("typeName", "刀片");
                } else if (toolPartsVo.getType().equals(2)) {
                    params.put("typeName", "工具系统");
                } else if (toolPartsVo.getType().equals(3)) {
                    params.put("typeName", "刀具");
                }
                ToolForkInfoEntity toolForkInfoEntity = toolForkInfoMapper.selectById(toolPartsVo.getId());
                //设置转换类型
                if (toolPartsVo.getType().equals(3)) {
//                    if (CollectionUtil.isNotEmpty(transferParamEntities)) {
//                        transferParamEntities.forEach(transferParamEntity -> {
//                            if (StringUtils.isNotEmpty(transferParamEntity.getToolManagementParamCode()) && toolForkInfoEntity.getType().startsWith(transferParamEntity.getToolManagementParamCode())) {
//                                toolPartParamVo.setType(transferParamEntity.getUgParam());
//                            }
//                        });
//                    }
                    QueryWrapper<TransferParamChild> wrapper = new QueryWrapper<>();
                    wrapper.eq("tool_management_param_code" , toolForkInfoEntity.getType());
                    List<TransferParamChild> transferParamChildren = transferParamChildMapper.selectList(wrapper);
                    if(CollectionUtil.isNotEmpty(transferParamChildren)){
                        toolPartParamVo.setType(transferParamChildren.get(0).getUgParam());
                    }
                }
                List<ToolParamVo> parameters = JSONArray.parseArray(toolForkInfoEntity.getParameters(), ToolParamVo.class);
                if (CollectionUtil.isNotEmpty(parameters)) {
                    parameters.forEach(parameter -> {
                        params.put(parameter.getNameEn(), parameter.getValue());
                    });
                    //设置type字段
                    QueryWrapper<TypeItemEntity> typeItemWrapper = new QueryWrapper<>();
                    typeItemWrapper.eq("type", toolForkInfoEntity.getType());
                    TypeItemEntity typeItemEntity = typeItemMapper.selectOne(typeItemWrapper);
                    //设置库存数量
                    Integer stock = toolInventoryLocationRespository.selectStockNumber(toolForkInfoEntity.getId());
                    params.put("stockNumber", ObjectUtil.isNotNull(stock)? stock:0);
                    params.put("type", typeItemEntity.getTypeName());

                }
                paramsList.add(params);
            });
        }
        toolPartParamVo.setParams(paramsList);
        return toolPartParamVo;
    }

    public Object GetToolReload(String id, String department) {
        List<ToolPartParamVo> resultList = new ArrayList<>();
        if(StringUtils.isBlank(id)){
            return resultList;
        }
        List<AssemblyToolTypeEntity> assemblyToolTypeEntities = getAssemblyToolTypeEntitiesReload(id, department);
        if (CollectionUtil.isEmpty(assemblyToolTypeEntities)) {
            return resultList;
        }
        assemblyToolTypeEntities = assemblyToolTypeEntities.stream().filter(assemblyToolTypeEntity -> StringUtils.isNotBlank(assemblyToolTypeEntity.getName())).collect(Collectors.toList());
        assemblyToolTypeEntities.forEach( assemblyToolTypeEntity -> {
            List<Map<String, Object>> paramsList = new ArrayList<>();
            ToolPartParamVo toolPartParamVo = new ToolPartParamVo();
            toolPartParamVo.setID(assemblyToolTypeEntity.getToolNo());
            toolPartParamVo.setType(assemblyToolTypeEntity.getType());
            toolPartParamVo.setName(assemblyToolTypeEntity.getName());
            //转换类型
            String partIds = assemblyToolTypeEntity.getPartIds();
            List<ToolPartsVos> toolPartsVos = JSONArray.parseArray(partIds, ToolPartsVos.class);
            if (CollectionUtil.isNotEmpty(toolPartsVos)) {
                List<TransferParamEntity> transferParamEntities = transferParamMapper.selectList(new QueryWrapper<>());
                toolPartsVos.forEach(toolPartsVo -> {
                    Map<String, Object> params = new HashMap<>();
                    if (toolPartsVo.getType().equals(1)) {
                        params.put("typeName", "刀片");
                    } else if (toolPartsVo.getType().equals(2)) {
                        params.put("typeName", "工具系统");
                    } else if (toolPartsVo.getType().equals(3)) {
                        params.put("typeName", "刀具");
                    }
                    ToolForkInfoEntity toolForkInfoEntity = toolForkInfoMapper.selectById(toolPartsVo.getId());
                    //设置转换类型
                    if (toolPartsVo.getType().equals(3)) {
                        if (CollectionUtil.isNotEmpty(transferParamEntities)) {
                            transferParamEntities.forEach(transferParamEntity -> {
                                if (StringUtils.isNotEmpty(transferParamEntity.getToolManagementParamCode()) && toolForkInfoEntity.getType().startsWith(transferParamEntity.getToolManagementParamCode())) {
                                    toolPartParamVo.setType(transferParamEntity.getUgParam());
                                }
                            });
                        }
                    }
                    List<ToolParamVo> parameters = JSONArray.parseArray(toolForkInfoEntity.getParameters(), ToolParamVo.class);
                    if (CollectionUtil.isNotEmpty(parameters)) {
                        parameters.forEach(parameter -> {
                            params.put(parameter.getNameEn(), parameter.getValue());
                        });
                        //设置type字段
                        QueryWrapper<TypeItemEntity> typeItemWrapper = new QueryWrapper<>();
                        typeItemWrapper.eq("type", toolForkInfoEntity.getType());
                        TypeItemEntity typeItemEntity = typeItemMapper.selectOne(typeItemWrapper);
                        //设置库存数量
                        Integer stock = toolInventoryLocationRespository.selectStockNumber(toolForkInfoEntity.getId());
                        params.put("stockNumber", ObjectUtil.isNotNull(stock)? stock:0);
                        params.put("type", typeItemEntity.getTypeName());

                    }
                    paramsList.add(params);
                });
            }
            toolPartParamVo.setParams(paramsList);
            resultList.add(toolPartParamVo);
        });
        return resultList;
    }

    private List<AssemblyToolTypeEntity> getAssemblyToolTypeEntitiesReload(String id, String department) {
        List<Integer> userIds = getUserListByDepartment(department);
        QueryWrapper<AssemblyToolTypeEntity> wrapper = new QueryWrapper<>();
        wrapper.in("user_id", userIds);
        wrapper.like("tool_no", id);
        List<AssemblyToolTypeEntity> assemblyToolTypeEntities = assemblyToolTypeMapper.selectList(wrapper);
        return assemblyToolTypeEntities;
    }

    private String transToolNoToUgParam(List<ToolPartsVos> toolPartsVos) {
        String ugType = "";
        if (CollectionUtil.isNotEmpty(toolPartsVos)) {
            List<TransferParamEntity> transferParamEntities = transferParamMapper.selectList(new QueryWrapper<>());
            for (ToolPartsVos toolPartsVo : toolPartsVos) {
                if(toolPartsVo.getType().equals(3)){
                    ToolForkInfoEntity toolForkInfoEntity = toolForkInfoMapper.selectById(toolPartsVo.getId());
                    if (CollectionUtil.isNotEmpty(transferParamEntities)) {
                        for (TransferParamEntity transferParamEntity : transferParamEntities) {
                            if (StringUtils.isNotEmpty(transferParamEntity.getToolManagementParamCode()) && toolForkInfoEntity.getType().startsWith(transferParamEntity.getToolManagementParamCode())) {
                                ugType = transferParamEntity.getUgParam();
                            }
                        }
                    }
                }
            }
            return ugType;
        }
        return "";
    }

    private List<AssemblyToolTypeEntity> getAssemblyToolTypeEntities(String id, String department , String name) {
        List<Integer> userIds = getUserListByDepartment(department);
        QueryWrapper<AssemblyToolTypeEntity> wrapper = new QueryWrapper<>();
        wrapper.in("user_id", userIds);
        wrapper.eq("tool_no", id);
        wrapper.eq("name" , name);
        List<AssemblyToolTypeEntity> assemblyToolTypeEntities = assemblyToolTypeMapper.selectList(wrapper);
        return assemblyToolTypeEntities;
    }

    public Object getToolCuttingParam(String id, String department , String name) throws ToolManageException {
        ToolCuttingParamVo toolCuttingParamVo = new ToolCuttingParamVo();
        toolCuttingParamVo.setID(id);
        List<AssemblyToolTypeEntity> assemblyToolTypeEntities = getAssemblyToolTypeEntities(id, department,name);
        if (CollectionUtil.isEmpty(assemblyToolTypeEntities)) {
            throw new ToolManageException(ToolManageEx.TOOL_ID_NO_EXIT.getCode(), ToolManageEx.TOOL_ID_NO_EXIT.getMsg());
        }
        assemblyToolTypeEntities = assemblyToolTypeEntities.stream().filter(assemblyToolTypeEntity -> StringUtils.isNotBlank(assemblyToolTypeEntity.getName()) && StringUtils.isNotBlank(assemblyToolTypeEntity.getToolNo())).collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(assemblyToolTypeEntities)) {
            AssemblyToolTypeEntity assemblyToolTypeEntity = assemblyToolTypeEntities.get(0);
            toolCuttingParamVo.setName(assemblyToolTypeEntity.getName());
            List<ToolPartsVos> toolPartsVos = JSONArray.parseArray(assemblyToolTypeEntity.getPartIds(), ToolPartsVos.class);
            toolCuttingParamVo.setType(transToolNoToUgParam(toolPartsVos));
            if (StringUtils.isNotBlank(assemblyToolTypeEntity.getParameters())
                    && !"[]".equals(assemblyToolTypeEntity.getParameters())) {
                List<AssemblyToolParamVo> assemblyToolParamVos = JSONArray.parseArray(assemblyToolTypeEntity.getParameters(), AssemblyToolParamVo.class);
                toolCuttingParamVo.setToolCuttingParam(assemblyToolParamVos);
            }
        }
        return toolCuttingParamVo;
    }

    public Object editAssemblyToolCuttingParams(EditAssemblyToolParamsReq editAssemblyToolParamsReq) throws ToolManageException{
        if (ObjectUtil.isNull(editAssemblyToolParamsReq.getId())) {
            throw new ToolManageException(ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getCode(), ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getMsg());
        }
        AssemblyToolTypeEntity assemblyToolTypeEntity = assemblyToolTypeMapper.selectById(editAssemblyToolParamsReq.getId());
        if (ObjectUtil.isNull(assemblyToolTypeEntity)) {
            throw new ToolManageException(ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getCode(), ToolManageEx.ASSEMBLY_TOOL_ID_NULL.getMsg());
        }
        assemblyToolTypeEntity.setParameters(JSONObject.toJSONString(transferParam(editAssemblyToolParamsReq.getAssemblyToolParamVos())));
        assemblyToolTypeMapper.updateById(assemblyToolTypeEntity);
        return null;
    }

    public List<AssemblyToolParamVo> transferParam(List<AssemblyToolParamVo> assemblyToolParamVos){
        //获取集合中最大id
        if(CollectionUtil.isNotEmpty(assemblyToolParamVos)){
            List<Integer> indexs = assemblyToolParamVos
                    .stream()
                    .filter(assemblyToolParamVo -> ObjectUtil.isNotNull(assemblyToolParamVo.getIndex()))
                    .map(AssemblyToolParamVo::getIndex)
                    .collect(Collectors.toList());
            Integer index = 0;
            if(CollectionUtil.isNotEmpty(indexs)){
                index = ObjectUtil.isNotNull(CollectionUtil.max(indexs))? CollectionUtil.max(indexs) : 1;
            }
            for (AssemblyToolParamVo assemblyToolParamVo : assemblyToolParamVos) {
                if(ObjectUtil.isNull(assemblyToolParamVo.getIndex())){
                    index = index +1;
                    assemblyToolParamVo.setIndex(index);
                }
            }
            return assemblyToolParamVos;
        }
        return new ArrayList<>();
    }

    public Object getTransferParamCode() {
        List<TransferParamChild> transferParamEntities = transferParamChildMapper.selectList(new QueryWrapper<>());
        List<TransferParamChild> updateList = new ArrayList<>();
        if(CollectionUtil.isNotEmpty(transferParamEntities)){
            for (TransferParamChild transferParamEntity : transferParamEntities) {
                transferParamEntity.setToolManagementParamCode(typeItemMapper.selectCodeByTypeName(transferParamEntity.getToolManagementParam()));
                updateList.add(transferParamEntity);
            }
        }
        if(CollectionUtil.isNotEmpty(updateList)){
            transferParamChildMapper.updateBatchById(updateList);
        }
        return null;
    }

    public Object checkAssemblyExist(Integer assemblyToolId) throws ToolManageException, IOException {
        String token = CommonUtil.getToken();
        Map<String , String> retMap = new HashMap<>();
        AssemblyToolTypeEntity assemblyToolTypeEntity = assemblyToolTypeMapper.selectById(assemblyToolId);
        if(ObjectUtil.isNull(assemblyToolTypeEntity)){
            return retMap;
        }
        //检查是否自定义了装配
        QueryWrapper<AssemblyMountingDistanceEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("tool_fork_info_id" ,assemblyToolTypeEntity.getToolId());
        wrapper.eq("assembly_tool_type_id" , assemblyToolTypeEntity.getId());
        AssemblyMountingDistanceEntity assemblyMountingDistanceEntity = assemblyMountingDistanceMapper.selectOne(wrapper);
        if(ObjectUtil.isNotNull(assemblyMountingDistanceEntity)){
            throw new ToolManageException(ToolManageEx.NO_EXIST_MODEL.getCode(), ToolManageEx.NO_EXIST_MODEL.getMsg());
        }

        ToolForkInfoEntity toolEntity = null;
        String type = "";
        String image = "";
        String twoDimensionalModel = "";
        String threeDimensionalModel = "";
        String threeDimensionalModelStl = "";
        StringBuilder guidList = new StringBuilder();

        List<ToolPartsVos> toolPartsVos = new ArrayList<>();
        Map<Integer , ToolForkInfoEntity> groupByIdMap = new HashMap<>();
        if(StringUtils.isNotBlank(assemblyToolTypeEntity.getPartIds())){
            toolPartsVos = JSONArray.parseArray(assemblyToolTypeEntity.getPartIds() , ToolPartsVos.class);
            List<ToolForkInfoEntity> toolForkInfoEntities = toolForkInfoRespository.selectByIds(toolPartsVos.stream().map(ToolPartsVos::getId).collect(Collectors.toList()));
            if(CollectionUtil.isNotEmpty(toolForkInfoEntities)){
                groupByIdMap = toolForkInfoEntities.stream().collect(Collectors.toMap(ToolForkInfoEntity::getId , ToolForkInfoEntity-> ToolForkInfoEntity));
            }
        }
        if(ObjectUtil.isNotNull(assemblyToolTypeEntity)){
            if(CollectionUtil.isNotEmpty(toolPartsVos)){
                for (ToolPartsVos toolPartsVo : toolPartsVos) {
                    if(ObjectUtil.isNotNull(toolPartsVo) && toolPartsVo.getType() ==3){
                        toolEntity = groupByIdMap.get(toolPartsVo.getId());
                    }
                    guidList.append(toolPartsVo.getGuid()).append(";");
                }
                if(ObjectUtil.isNotNull(toolEntity) && StringUtils.isNotBlank(toolEntity.getOriginalParams())){
                    JSONObject jsonObject = JSONObject.parseObject(toolEntity.getOriginalParams());
                    if(StringUtils.isNotBlank(jsonObject.get("type").toString())){
                        type = jsonObject.get("type").toString();
                    }
                }
            }
            if(StringUtils.isNotBlank(type) && StringUtils.isNotBlank(guidList.toString())){
                Map<String , Object> paramMap = new HashMap<>();
                paramMap.put("token" , token);
                paramMap.put("type" , type);
                paramMap.put("guidList" , guidList.toString());
                String post = HttpUtil.post(CommonConstant.USAGE_ADRESS +"/ZeusoftWebService.svc/api/CheckAssembly", JSONObject.toJSONString(paramMap));
                if(StringUtils.isNotBlank(post)){
                    JSONObject jsonObject = JSONObject.parseObject(post);
                    if(ObjectUtil.isNotNull(jsonObject.get("result")) && "True".equals(jsonObject.get("result").toString())){
                        //请求装配任务接口
                        boolean flag = true;
                        JSONObject jsonObject2 = JSONObject.parseObject(toolEntity.getOriginalParams());
                        if(ObjectUtil.isNotNull(jsonObject2.get("partModelUri")) && ObjectUtil.isNotNull(jsonObject2.get("simplePartModelUri")) && jsonObject2.get("partModelUri").toString().equals(jsonObject2.get("simplePartModelUri").toString())){
                            flag = false;
                        }
                        if(flag){
                            //基本和详细
                            twoAssemble(assemblyToolTypeEntity , paramMap ,  image , twoDimensionalModel , threeDimensionalModel , threeDimensionalModelStl);
                        }else {
                            //详细
                            oneAssemble(assemblyToolTypeEntity , paramMap , "false" , image , twoDimensionalModel , threeDimensionalModel , threeDimensionalModelStl);
                        }
                        if(StringUtils.isNotBlank(assemblyToolTypeEntity.getImage()) && StringUtils.isBlank(minioHelper.downloadGetObjectUrlReload(assemblyToolTypeEntity.getImage()))){
                            minioHelper.uploadFileWithNetFile(assemblyToolTypeEntity.getImage());
                        }else if(StringUtils.isNotBlank(assemblyToolTypeEntity.getTwoDimensionalModel()) && StringUtils.isBlank(minioHelper.downloadGetObjectUrlReload(assemblyToolTypeEntity.getTwoDimensionalModel()))){
                            minioHelper.uploadFileWithNetFile(assemblyToolTypeEntity.getTwoDimensionalModel());
                        }else if(StringUtils.isNotBlank(assemblyToolTypeEntity.getThreeDimensionalModel()) && StringUtils.isBlank(minioHelper.downloadGetObjectUrlReload(assemblyToolTypeEntity.getThreeDimensionalModel()))){
                            minioHelper.uploadFileWithNetFile(assemblyToolTypeEntity.getThreeDimensionalModel());
                        }else if(StringUtils.isNotBlank(assemblyToolTypeEntity.getThreeDimensionalModelStl()) && StringUtils.isBlank(minioHelper.downloadGetObjectUrlReload(assemblyToolTypeEntity.getThreeDimensionalModelStl()))){
                            minioHelper.uploadFileWithNetFile(assemblyToolTypeEntity.getThreeDimensionalModelStl());
                        }
                        assemblyToolTypeMapper.updateById(assemblyToolTypeEntity);
                    }
                }
            }
        }
        retMap.put("image" , assemblyToolTypeEntity.getImage());
        retMap.put("twoDimensionalModel" , assemblyToolTypeEntity.getTwoDimensionalModel());
        retMap.put("threeDimensionalModel" , assemblyToolTypeEntity.getThreeDimensionalModel());
        retMap.put("threeDimensionalModelStl" , assemblyToolTypeEntity.getThreeDimensionalModelStl());
        return retMap;
    }

    private void oneAssemble(AssemblyToolTypeEntity assemblyToolTypeEntity , Map<String , Object> paramMap , String flag , String image , String twoDimensionalModel , String threeDimensionalModel , String threeDimensionalModelStl){
        paramMap.put("isBasic" , flag);
        //System.out.println("JSONObject.toJSONString(paramMap) = " + JSONObject.toJSONString(paramMap));
        String post2 = HttpUtil.post(CommonConstant.USAGE_ADRESS + "/ZeusoftWebService.svc/api/GetAssemblyInfo", JSONObject.toJSONString(paramMap));
        if(StringUtils.isNotBlank(post2)){
            JSONObject urlObject = JSONObject.parseObject(post2);
            UrlVo urlVo = JSONObject.parseObject(urlObject.get("result").toString() , UrlVo.class);
            if(StringUtils.isNotBlank(urlVo.getDrawPdfPath())){
                image = urlVo.getDrawPdfPath();
                assemblyToolTypeEntity.setImage(image);
            }
            if(StringUtils.isNotBlank(urlVo.getModelPngPath())){
                twoDimensionalModel = urlVo.getModelPngPath();
                assemblyToolTypeEntity.setTwoDimensionalModel(twoDimensionalModel);
            }
            if(StringUtils.isNotBlank(urlVo.getStpPath())){
                threeDimensionalModel = urlVo.getStpPath();
                assemblyToolTypeEntity.setThreeDimensionalModel(threeDimensionalModel);
            }
            if(StringUtils.isNotBlank(urlVo.getViewerUrl())){
                threeDimensionalModelStl = urlVo.getViewerUrl();
                assemblyToolTypeEntity.setThreeDimensionalModelStl(threeDimensionalModelStl);
            }
            //assemblyToolTypeMapper.updateById(assemblyToolTypeEntity);
        }
    }

    private void twoAssemble(AssemblyToolTypeEntity assemblyToolTypeEntity , Map<String , Object> paramMap , String image , String twoDimensionalModel , String threeDimensionalModel , String threeDimensionalModelStl){
        paramMap.put("isBasic" , "true");
        //System.out.println("JSONObject.toJSONString(paramMap) = " + JSONObject.toJSONString(paramMap));
        String post2 = HttpUtil.post(CommonConstant.USAGE_ADRESS + "/ZeusoftWebService.svc/api/GetAssemblyInfo", JSONObject.toJSONString(paramMap));
        if(StringUtils.isNotBlank(post2)){
            JSONObject urlObject = JSONObject.parseObject(post2);
            UrlVo urlVo = JSONObject.parseObject(urlObject.get("result").toString() , UrlVo.class);
            if(StringUtils.isNotBlank(urlVo.getDrawPdfPath())){
                image = urlVo.getDrawPdfPath();
                assemblyToolTypeEntity.setImage(image);
            }
            if(StringUtils.isNotBlank(urlVo.getModelPngPath())){
                twoDimensionalModel = urlVo.getModelPngPath();
                assemblyToolTypeEntity.setTwoDimensionalModel(twoDimensionalModel);
            }
            if(StringUtils.isNotBlank(urlVo.getStpPath())){
                threeDimensionalModel = urlVo.getStpPath();
                assemblyToolTypeEntity.setThreeDimensionalModel(threeDimensionalModel);
            }
            if(StringUtils.isNotBlank(urlVo.getViewerUrl())){
                threeDimensionalModelStl = urlVo.getViewerUrl();
                assemblyToolTypeEntity.setThreeDimensionalModelStl(threeDimensionalModelStl);
            }
            //assemblyToolTypeMapper.updateById(assemblyToolTypeEntity);
        }
        paramMap.put("isBasic" , "false");
        //System.out.println("JSONObject.toJSONString(paramMap) = " + JSONObject.toJSONString(paramMap));
        String post3 = HttpUtil.post(CommonConstant.USAGE_ADRESS + "/ZeusoftWebService.svc/api/GetAssemblyInfo", JSONObject.toJSONString(paramMap));
        if(StringUtils.isNotBlank(post3)){
            JSONObject urlObject = JSONObject.parseObject(post3);
            UrlVo urlVo = JSONObject.parseObject(urlObject.get("result").toString() , UrlVo.class);
            if(StringUtils.isNotBlank(urlVo.getDrawPdfPath())){
                image = urlVo.getDrawPdfPath();
                assemblyToolTypeEntity.setImage(image);
            }
            if(StringUtils.isNotBlank(urlVo.getModelPngPath())){
                twoDimensionalModel = urlVo.getModelPngPath();
                assemblyToolTypeEntity.setTwoDimensionalModel(twoDimensionalModel);
            }
            if(StringUtils.isNotBlank(urlVo.getStpPath())){
                threeDimensionalModel = urlVo.getStpPath();
                assemblyToolTypeEntity.setThreeDimensionalModel(threeDimensionalModel);
            }
            if(StringUtils.isNotBlank(urlVo.getViewerUrl())){
                threeDimensionalModelStl = urlVo.getViewerUrl();
                assemblyToolTypeEntity.setThreeDimensionalModelStl(threeDimensionalModelStl);
            }
        }
    }

    public Object RunAssemblyTask(Integer assemblyToolId) {
        String token = CommonUtil.getToken();

        List<AssembleTaskEntity> insertList = new ArrayList<>();
        //校验是否发送过该请求
//        QueryWrapper wrapper = new QueryWrapper<AssembleTaskEntity>();
//        wrapper.eq("assembly_tool_type_id" , assemblyToolId);
//        List<AssembleTaskEntity> assembleTaskEntities = assembleTaskMapper.selectList(wrapper);
//        if(CollectionUtil.isNotEmpty(assembleTaskEntities)){
//            return Boolean.FALSE;
//        }
        //基本
        Map<String , Object> simpleMap = new HashMap<>();
        //详细
        Map<String , Object> detailMap = new HashMap<>();

        String simpleTaskId = "simple" + UUIDUtil.getUUID();

        String detailTaskId = "detail" + UUIDUtil.getUUID();

        simpleMap.put("taskId" , simpleTaskId);
        detailMap.put("taskId" , detailTaskId);

        simpleMap.put("token" , token);
        detailMap.put("token" , token);
        AssemblyToolTypeEntity assemblyToolTypeEntity = assemblyToolTypeMapper.selectById(assemblyToolId);
        if(ObjectUtil.isNull(assemblyToolTypeEntity)){
            return Boolean.FALSE;
        }
        ToolForkInfoEntity toolEntity = null;
        List<ToolPartsVos> toolPartsVos = new ArrayList<>();
        Map<Integer , ToolForkInfoEntity> groupByIdMap = new HashMap<>();
        if(StringUtils.isNotBlank(assemblyToolTypeEntity.getPartIds())){
            toolPartsVos = JSONArray.parseArray(assemblyToolTypeEntity.getPartIds() , ToolPartsVos.class);
            List<ToolForkInfoEntity> toolForkInfoEntities = toolForkInfoRespository.selectByIds(toolPartsVos.stream().map(ToolPartsVos::getId).collect(Collectors.toList()));
            if(CollectionUtil.isNotEmpty(toolForkInfoEntities)){
                groupByIdMap = toolForkInfoEntities.stream().collect(Collectors.toMap(ToolForkInfoEntity::getId , ToolForkInfoEntity-> ToolForkInfoEntity));
            }
        }
        if(ObjectUtil.isNotNull(assemblyToolTypeEntity)){
            List<RequestVo> objectList = new ArrayList();
            //toolEntity = toolForkInfoMapper.selectById(assemblyToolTypeEntity.getToolId());
            toolEntity = groupByIdMap.get(assemblyToolTypeEntity.getToolId());
            boolean flag = true;
            JSONObject jsonObject2 = JSONObject.parseObject(toolEntity.getOriginalParams());

            //获取objectList
            if(CollectionUtil.isNotEmpty(toolPartsVos)){
                //List<ToolPartsVos> toolPartsVos = JSONArray.parseArray(assemblyToolTypeEntity.getPartIds() , ToolPartsVos.class);
                for (ToolPartsVos toolPartsVo : toolPartsVos) {
                    RequestVo requestVo = new RequestVo();
                    //ToolForkInfoEntity toolForkInfoEntity = toolForkInfoMapper.selectById(toolPartsVo.getId());
                    ToolForkInfoEntity toolForkInfoEntity = groupByIdMap.get(toolPartsVo.getId());
                    JSONObject partJsonObject = JSONObject.parseObject(toolForkInfoEntity.getOriginalParams());
                    requestVo.setPath(ObjectUtil.isNotNull(partJsonObject.get("partModelUri"))? partJsonObject.get("partModelUri").toString() : "");
                    requestVo.setBasicPath(ObjectUtil.isNotNull(partJsonObject.get("simplePartModelUri"))? partJsonObject.get("simplePartModelUri").toString() : "");
                    //刀具
                    if(toolPartsVo.getType() == 3){
//                        if(ObjectUtil.isNotNull(partJsonObject.get("Z"))){
//                            requestVo.setIsBladeClamp("true");
//                        }
                        requestVo.setIsBladeClamp("true");
                        QueryWrapper<AssemblyMountingDistanceEntity> distanceWrapper = new QueryWrapper<>();
                        distanceWrapper.eq("tool_fork_info_id" , toolPartsVo.getId());
                        distanceWrapper.eq("assembly_tool_type_id" , toolPartsVo.getId());
                        AssemblyMountingDistanceEntity assemblyMountingDistanceEntity = assemblyMountingDistanceMapper.selectOne(distanceWrapper);
                        if(ObjectUtil.isNotNull(assemblyMountingDistanceEntity) && ObjectUtil.isNotNull(assemblyMountingDistanceEntity.getId())){
                            requestVo.setZ(assemblyMountingDistanceEntity.getMountingDistance().toString());
                        }
                    }
                    //刀片
                    if(toolPartsVo.getType() == 1){
                        if(ObjectUtil.isNotNull(partJsonObject.get("WIPER_CODE")) && partJsonObject.get("WIPER_CODE").toString().equals("1")){
                            requestVo.setIsLightBlade("true");
                        }else {
                            requestVo.setIsBlade("true");
                        }
                    }
                    requestVo.setNum(toolPartsVo.getNumber().toString());
                    objectList.add(requestVo);
                }
            }

            if(ObjectUtil.isNotNull(jsonObject2.get("partModelUri")) && ObjectUtil.isNotNull(jsonObject2.get("simplePartModelUri")) && jsonObject2.get("partModelUri").toString().equals(jsonObject2.get("simplePartModelUri").toString())){
                flag = false;
            }
            if(flag){
                //不同的情况下，执行两个
                if(StringUtils.isNotBlank(assemblyToolTypeEntity.getPartIds())){
                    //List<ToolPartsVos> toolPartsVos = JSONArray.parseArray(assemblyToolTypeEntity.getPartIds() , ToolPartsVos.class);
                    for (ToolPartsVos toolPartsVo : toolPartsVos) {
                        if(toolPartsVo.getType() == 2){
                            simpleMap.put("hasHilt" , "1");
                        }
                    }
                    if(ObjectUtil.isNull(simpleMap.get("hasHilt"))){
                        simpleMap.put("hasHilt" , "0");
                    }
                }

                simpleMap.put("draw" , "");
                simpleMap.put("stp" , "");
                simpleMap.put("taskType" , 11);
                simpleMap.put("objList" , JSONArray.toJSON(transferParamReload(objectList)));
                //发送基础请求
                String simplePost = HttpUtil.post(CommonConstant.USAGE_ADRESS + "/ZeusoftWebService.svc/api/RunAssemlyTask", JSONObject.toJSONString(simpleMap));
                if(StringUtils.isNotBlank(simplePost)){
                    if(JSONObject.parseObject(simplePost).get("result").equals("true")){
                        AssembleTaskEntity assembleTaskEntity = new AssembleTaskEntity();
                        assembleTaskEntity.setTaskId(simpleTaskId);
                        assembleTaskEntity.setAssemblyToolTypeId(assemblyToolId);
                        assembleTaskEntity.setTypeFlag(0);
                        insertList.add(assembleTaskEntity);
                    }
                }
            }
            //相同的情况下执行详细
            detailMap.put("hasHilt" , "");
            if(StringUtils.isNotBlank(assemblyToolTypeEntity.getType()) && assemblyToolTypeEntity.getType().contains("车削")){
                detailMap.put("draw" , "0");
            }else {
                detailMap.put("draw" , "1");
            }
            detailMap.put("stp" , "1");
            detailMap.put("taskType" , 10);
            detailMap.put("objList" , JSONArray.toJSON(transferParamReload(objectList)));
            System.out.println(JSONObject.toJSONString(detailMap));
            //发送详细请求
            String detailPost = HttpUtil.post(CommonConstant.USAGE_ADRESS + "/ZeusoftWebService.svc/api/RunAssemlyTask", JSONObject.toJSONString(detailMap));
            if(StringUtils.isNotBlank(detailPost)){
                if(JSONObject.parseObject(detailPost).get("result").toString().equals("true")){
                    AssembleTaskEntity assembleTaskEntity = new AssembleTaskEntity();
                    assembleTaskEntity.setTaskId(detailTaskId);
                    assembleTaskEntity.setAssemblyToolTypeId(assemblyToolId);
                    assembleTaskEntity.setTypeFlag(1);
                    insertList.add(assembleTaskEntity);
                }
            }
        }
        if(CollectionUtil.isNotEmpty(insertList)){
            assembleTaskMapper.insertBatchSomeColumn(insertList);
        }
        return Boolean.TRUE;
    }

    private List<Map<String , Object>> transferParamReload(List<RequestVo> requestVos){
        List<Map<String , Object>> objectList = new ArrayList<>();
        if(CollectionUtil.isNotEmpty(requestVos)){
            for (RequestVo requestVo : requestVos) {
                Map<String , Object> objectMap = new HashMap<>();
                objectMap.put("Path" , requestVo.getPath());
                objectMap.put("BasicPath" , requestVo.getBasicPath());
                objectMap.put("Num" , requestVo.getNum());
                objectMap.put("Za" , requestVo.getZa());
                objectMap.put("Z" , requestVo.getZ());
                objectMap.put("X" , requestVo.getX());
                objectMap.put("Ya" , requestVo.getYa());
                objectMap.put("Y" , requestVo.getY());
                objectMap.put("Xa" , requestVo.getXa());
                objectMap.put("IsBladeClamp" , requestVo.getIsBladeClamp());
                objectMap.put("IsBlade" , requestVo.getIsBlade());
                objectMap.put("IsLightBlade" , requestVo.getIsLightBlade());
                objectList.add(objectMap);
            }
        }
        return objectList;
    }

    public Object changeAssemblyTool() {
        QueryWrapper<AssemblyToolTypeEntity> wrapper = new QueryWrapper<>();
        wrapper.ne("id" , 50);
        List<AssemblyToolTypeEntity> list = assemblyToolTypeMapper.selectList(wrapper);
        List<AssemblyToolTypeEntity> updateList = new ArrayList<>();
        for (AssemblyToolTypeEntity assemblyToolTypeEntity : list) {
            List<ToolPartVoReload> toolPartVoReloads = JSONArray.parseArray(assemblyToolTypeEntity.getPartIds() , ToolPartVoReload.class);
            List<ToolPartsVos> newList = new ArrayList<>();
            if(CollectionUtil.isNotEmpty(toolPartVoReloads)){
                for (ToolPartVoReload toolPartVoReload : toolPartVoReloads) {
                    ToolPartsVos toolPartsVos = new ToolPartsVos();
                    toolPartsVos.setId(toolPartVoReload.getId());
                    toolPartsVos.setNumber(1);
                    toolPartsVos.setType(toolPartVoReload.getType());
                    toolPartsVos.setGuid(transferGuid(toolPartVoReload.getId()));
                    newList.add(toolPartsVos);
                }
                assemblyToolTypeEntity.setPartIds(JSONArray.toJSONString(newList));
                updateList.add(assemblyToolTypeEntity);
            }
        }
        if(CollectionUtil.isNotEmpty(updateList)){
            assemblyToolTypeMapper.updateBatchById(updateList);
        }
        return Boolean.TRUE;
    }
    
    public String transferGuid(Integer id){
        ToolForkInfoEntity toolEntity = toolForkInfoMapper.selectById(id);
        List<ToolParamVo> toolParamVos = JSONArray.parseArray(toolEntity.getParameters() , ToolParamVo.class);
        for (ToolParamVo toolParamVo : toolParamVos) {
            if(toolParamVo.getNameEn().equals("guid")){
                return toolParamVo.getValue();
            }
        }
        return "";
    }

    public Object GetAssemblyTaskStatus(Integer assemblyToolId) throws ToolManageException, IOException {
        String token = CommonUtil.getToken();
        QueryWrapper<AssembleTaskEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("assembly_tool_type_id" , assemblyToolId);
        List<AssembleTaskEntity> assembleTaskEntities = assembleTaskMapper.selectList(wrapper);
        if(CollectionUtil.isEmpty(assembleTaskEntities)){
            throw new ToolManageException(ToolManageEx.NO_EXIST_MODEL_TASK.getCode(), ToolManageEx.NO_EXIST_MODEL_TASK.getMsg());
        }
        Map<String , Object> retMap = new HashMap<>();
        AssemblyToolTypeEntity assemblyToolTypeEntity = assemblyToolTypeMapper.selectById(assemblyToolId);
        for (AssembleTaskEntity assembleTaskEntity : assembleTaskEntities) {
            Map<String , Object> requestMap = new HashMap<>();
            requestMap.put("token" , token);
            requestMap.put("taskId" , assembleTaskEntity.getTaskId());
            retMap.put("simpleTask" , "");
            retMap.put("detailTask" , "");
            String post = HttpUtil.post(CommonConstant.USAGE_ADRESS + "/ZeusoftWebService.svc/api/GetAssemblyTaskStatus", JSONObject.toJSONString(requestMap));
            if(ObjectUtil.isNotNull(assembleTaskEntity.getTypeFlag()) && assembleTaskEntity.getTypeFlag() ==0){
                retMap.put("simpleTask" , JSONObject.parseObject(post));
            }else {
                retMap.put("detailTask" , JSONObject.parseObject(post));
            }
            if(StringUtils.isNotBlank(post)) {
                JSONObject urlObject = JSONObject.parseObject(post);
                UrlVo urlVo = JSONObject.parseObject(urlObject.get("result").toString(), UrlVo.class);
                if (StringUtils.isNotBlank(urlVo.getDrawPdfPath())) {
                    assemblyToolTypeEntity.setImage(urlVo.getDrawPdfPath());
                    if(StringUtils.isBlank(minioHelper.downloadGetObjectUrlReload(urlVo.getDrawPdfPath()))){
                        minioHelper.uploadFileWithNetFile(urlVo.getDrawPdfPath());
                    }
                }
                if (StringUtils.isNotBlank(urlVo.getModelPngPath())) {
                    assemblyToolTypeEntity.setTwoDimensionalModel(urlVo.getModelPngPath());
                    if(StringUtils.isBlank(minioHelper.downloadGetObjectUrlReload(urlVo.getModelPngPath()))){
                        minioHelper.uploadFileWithNetFile(urlVo.getModelPngPath());
                    }
                }
                if (StringUtils.isNotBlank(urlVo.getStpPath())) {
                    assemblyToolTypeEntity.setThreeDimensionalModel(urlVo.getStpPath());
                    if(StringUtils.isBlank(minioHelper.downloadGetObjectUrlReload(urlVo.getStpPath()))){
                        minioHelper.uploadFileWithNetFile(urlVo.getStpPath());
                    }
                }
                if (StringUtils.isNotBlank(urlVo.getViewerUrl())) {
                    assemblyToolTypeEntity.setThreeDimensionalModelStl(urlVo.getViewerUrl());
                    if(StringUtils.isBlank(minioHelper.downloadGetObjectUrlReload(urlVo.getViewerUrl()))){
                        minioHelper.uploadFileWithNetFile(urlVo.getViewerUrl());
                    }
                }
            }
        }
        assemblyToolTypeMapper.updateById(assemblyToolTypeEntity);
        //发送请求查询任务装配情况
        return retMap;
    }

    /**
     * 去重并插入
     * @param list
     */
    public void importNxParamsTransferExcel(List<ParseNxParamsTransferVo> list) {
        List<TransferParamChild> updateList = list.stream().map(this::transferChildVo).collect(Collectors.toList());
        List<TransferParamChild> transferParamChildren = transferParamChildMapper.selectList(new QueryWrapper<>());
        if(CollectionUtil.isNotEmpty(transferParamChildren)){
            transferParamChildren.forEach(transferParamChild -> transferParamChild.setDistinctColumn(transferParamChild.getUgParam()+transferParamChild.getToolManagementParam()));
            List<String> existList = transferParamChildren.stream().map(TransferParamChild::getDistinctColumn).collect(Collectors.toList());
            //去重
            updateList = updateList.stream().filter(transferParamChild ->CollectionUtil.isNotEmpty(existList) && !existList.contains(transferParamChild.getDistinctColumn())).collect(Collectors.toList());
        }
        //处理数据并插入
        dealWithDataAndPersist(updateList);
    }

    private void dealWithDataAndPersist(List<TransferParamChild> updateList) {
        if(CollectionUtil.isNotEmpty(updateList)){
            List<String> collect = updateList.stream().map(TransferParamChild::getToolManagementParam).collect(Collectors.toList());
            QueryWrapper<TypeItemEntity> wrapper = new QueryWrapper<>();
            wrapper.in("type_name" , collect);
            List<TypeItemEntity> typeItemEntities = typeItemMapper.selectList(wrapper);
            if(CollectionUtil.isNotEmpty(typeItemEntities)){
                Map<String, String> typeNameAndTypeCodeMap = typeItemEntities
                        .stream()
                        .filter(distinctByKey(TypeItemEntity::getTypeName))
                        .collect(Collectors.toMap(TypeItemEntity::getTypeName, TypeItemEntity::getType));
                updateList.forEach(transferParamChild -> transferParamChild.setToolManagementParamCode(typeNameAndTypeCodeMap.get(transferParamChild.getToolManagementParam())));
                //校验更新list大小 大于2000则分组插入
                if(updateList.size()>2000){
                    List<List<TransferParamChild>> lists = CommonUtil.groupList(updateList);
                    for (List<TransferParamChild> paramChildren : lists) {
                        transferParamChildMapper.insertBatchSomeColumn(paramChildren);
                    }
                }else {
                    transferParamChildMapper.insertBatchSomeColumn(updateList);
                }
            }
        }
    }

    /**
     * 删除并插入
     * @param list
     */
    public void importNxParamsTransferExcelReload(List<ParseNxParamsTransferVo> list) {
        List<TransferParamChild> updateList = list.stream().map(this::transferChildVo).collect(Collectors.toList());
        List<String> ugParams = updateList.stream().map(TransferParamChild::getUgParam).collect(Collectors.toList());
        QueryWrapper<TransferParamChild> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("ug_param" , ugParams);
        transferParamChildMapper.delete(queryWrapper);
        dealWithDataAndPersist(updateList);
    }

    static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
        Map<Object, Boolean> seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }

    private TransferParamChild transferChildVo(ParseNxParamsTransferVo parseNxParamsTransferVo) {
        TransferParamChild transferParamChild = new TransferParamChild();
        transferParamChild.setUgParam(parseNxParamsTransferVo.getNxParamName());
        transferParamChild.setToolManagementParam(parseNxParamsTransferVo.getToolManageParamName());
        transferParamChild.setDistinctColumn(parseNxParamsTransferVo.getUgParam()+parseNxParamsTransferVo.getToolManagementParam());
        return transferParamChild;
    }

//    public Object createAssemblyTool(CreateAssemblyToolReq createAssemblyToolReq){
//        QueryWrapper<TypeItemEntity> wrapper = new QueryWrapper<>();
//        wrapper.eq("type" , createAssemblyToolReq.getType());
//        TypeItemEntity typeItemEntity = typeItemMapper.selectOne(wrapper);
//        AssemblyToolTypeEntity assemblyToolTypeEntity = new AssemblyToolTypeEntity();
//        assemblyToolTypeEntity.setCode(UUIDUtil.getUUID());
//        assemblyToolTypeEntity.setName("总成"+"-"+assemblyToolTypeEntity.getCode().substring(0,5));
//        assemblyToolTypeEntity.setType(typeItemEntity.getTypeName());
//        assemblyToolTypeEntity.setTypeCode(createAssemblyToolReq.getType());
//        assemblyToolTypeMapper.insert(assemblyToolTypeEntity);
//        return Boolean.TRUE;
//    }
}
